﻿/**
 *	(C) 2014 Yuanjj
 *
 * 	define global object
 *
 *	histroy
 * 		2014-08-04	Yuanjj		-	create
 */

#ifndef _GLOBAL_H_
#define _GLOBAL_H_

#include 	"define.h"
#include 	"typedef.h"
#include 	"ui/bridge/html_bridge.h"
#include 	"routine/option/opt.h"
#include 	"routine/log/log.h"
#include 	"routine/tunnel/tunnel.h"
#include 	"routine/interface/db/db.h"
#include 	"routine/interface/net/net.h"
#include	"routine/threads/thread.h"
#include 	"routine/data/user/user.h"
#include 	"routine/data/event/event.h"

#define	DEFINE_GLOBAL_OBJECT( _extern_ )	\
            _extern_	cls_opt			g_opt;		\
            _extern_	cls_log			g_log;		\
            _extern_	cls_tunnel		g_tunnel;	\
            _extern_	cls_db			g_db;		\
            _extern_	cls_net			g_net;		\
            _extern_	cls_thread		g_thread;	\
            _extern_	cls_user		g_user;		\
            _extern_	cls_event		g_event;	\

DEFINE_GLOBAL_OBJECT( extern )

#define	OBJ_INSTANCE( _obj_, _res_, _lab_ )		\
            _res_ = _obj_.instance();			\
            IF_GOTO( 0 != _res_, _lab_ )

#define OBJS_INSTANCE( _res_, _lab_ )			\
            OBJ_INSTANCE( g_opt, _res_, _lab_ );		\
            OBJ_INSTANCE( g_log, _res_, _lab_ );		\
            OBJ_INSTANCE( g_tunnel, _res_, _lab_ );		\
            OBJ_INSTANCE( g_db, _res_, _lab_ );			\
            OBJ_INSTANCE( g_net, _res_, _lab_ );		\
            OBJ_INSTANCE( g_thread, _res_, _lab_ );		\

#define OBJS_RELEASE()				\
            g_thread.release();		\
            g_db.release();			\
            g_net.release();		\
            g_tunnel.release();

/**
 *	routine start
 */
pem_error_t routine_start( pem_s32_t argc, pem_s8_t* argv[] );

/**
 *	routine stop
 */
pem_void_t routine_stop( );

#endif // _GLOBAL_H_
